package com.example.tests;

//import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.junit.*;
//import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import com.opera.core.systems.OperaDriver;

public class HW1_1 {
	private WebDriver driver;
	private String baseUrl;

	@Test
	public void testUntitled() throws Exception {
		String [] browsers = {"chrome", "ie", "ff", "opera"};
		for(int i = 0; i <= browsers.length; i++)
		{
			driver = getWebDriver(browsers[i]);
			driver.get(baseUrl + "/php4dvd/");
			driver.findElement(By.id("username")).clear();
			driver.findElement(By.id("username")).sendKeys("admin");
			driver.findElement(By.name("password")).clear();
			driver.findElement(By.name("password")).sendKeys("admin");
			driver.findElement(By.name("submit")).click();
			driver.findElement(By.linkText("Log out")).click();
			// ERROR: Caught exception [ERROR: Unsupported command [getConfirmation]]
			driver.switchTo().alert().accept();
			driver.quit();
		}
	}
	
	public WebDriver getWebDriver(String browser)
	{
		switch(browser)
		{
		case "chrome":
			System.setProperty("webdriver.chrome.driver","D:\\_webDrivers\\chromedriver.exe");
			driver = new ChromeDriver();
			break;
		case "ff":
			driver = new FirefoxDriver();
			break;
		case "ie":
			System.setProperty("webdriver.ie.driver", "D:\\_webDrivers\\IEDriverServer.exe");
			driver = new InternetExplorerDriver();
			break;
		case "opera":
			driver = new OperaDriver();
			break;
		default:
			driver = new FirefoxDriver();
		}
		
		baseUrl = "http://localhost/";
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		return driver;
	}
}
